// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import iconSvg from '@/components/iconSvg'


Vue.config.productionTip = false

// 引入axios请求
Vue.config.productionTip = false
Vue.prototype.HTTP = 'http://nsapi.anasit.com';
// axios.defaults.baseURL = 'http://nsapi.anasit.com' // 正式版
axios.defaults.baseURL = 'http://nsapi.anasit.com' // 测试版
Vue.prototype.axios = axios
// fontIcon 若在阿里图标中添加了新图标,请在index.html中更新代码
Vue.component('icon-svg', iconSvg)

// // 添加Fastclick移除移动端点击延迟
// const FastClick = require('fastclick')
// FastClick.attach(document.body)

router.beforeEach((to, from, next) => {
  // this.axios.get('/wx/login/auth')
  // .then(res => {
  //     if (res.data.result) {
  //         _this.orders = _this.orders.concat(res.data.datas.rows);
  //         this.ifShow = false
  //     } else {
  //         this.orders = []
  //         this.ifShow = true
  //     }
  //     this.total = res.data.datas.total;
  // }, function(err) {
  //     console.log(err);
  // })
  if (to.meta.auth) {
      if (process.env.NODE_ENV == 'development') { //开发环境
          // store.commit('getOpenid', 'ou0Ez1MhlFFdR12Bvs72bnYxQoWE')
          // sessionStorage.setItem('openid', 'oajse0aHO-bQEh0OHbIJIHuNDAJE')
          sessionStorage.setItem('openid', 'o-37usxE6mVetx1xAhroaJ8joVGo')
          
          next();
      } else { //上线环境
          if (to.query.openid != undefined) {
              // store.commit('getOpenid', to.query.openid)
            //   sessionStorage.setItem('openid', to.query.openid)
            sessionStorage.setItem('openid', 'o-37usxE6mVetx1xAhroaJ8joVGo')
          }
          // if(store.state.user.openid){
          if (sessionStorage.getItem('openid')) {

              next();
          } else {
              // next();
              //正式版
              // var redirect_uri = "http://sljspapi.anasit.com/wechat/redirect/url?page=http://sljsp.anasit.com" + to.fullPath
              //     //测试版
              //     var redirect_uri = "http://sljspapi.anasit.com/wechat/redirect/url?page=http://nsapi.anasit.com" + to.fullPath
              // window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxb2cc0a549df3882c&redirect_uri=" + encodeURIComponent(redirect_uri) + "&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
              window.location.href = "http://nsapi.anasit.com/wx/login/auth"
          }
      }
  } else {
      next();
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
})
